package com.binarywang.spring.starter.wxjava.tp.config;

import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.cp.config.WxCpTpConfigStorage;
import me.chanjar.weixin.cp.tp.service.WxCpTpService;
import me.chanjar.weixin.cp.tp.service.impl.WxCpTpServiceImpl;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 企业微信平台相关服务自动注册
 *
 * @author yl
 * created on  2021/12/6
 */
@Configuration
@RequiredArgsConstructor
public class WxCpServiceAutoConfiguration {


  @Bean
  @ConditionalOnMissingBean
  @ConditionalOnBean(WxCpTpConfigStorage.class)
  public WxCpTpService wxCpService(WxCpTpConfigStorage wxCpTpConfigStorage) {
    WxCpTpService wxCpTpService = new WxCpTpServiceImpl();
    wxCpTpService.setWxCpTpConfigStorage(wxCpTpConfigStorage);

    return wxCpTpService;
  }
}
